(function (window) {
	'use strict';

	// Your starting point. Enjoy the ride!

	var vm = new Vue({
		el: '#app',
		data: {
			lists: [{
					text: '吃饭',
					isSelect: true
				},
				{
					text: '睡觉',
					isSelect: false
				},
				{
					text: '刷牙',
					isSelect: false
				},
				{
					text: '工作',
					isSelect: false
				}
			],
			message:'',
			editIndex:'',
			liststatus:'all'
		},
		computed:  {
			clickSelAll:{
				//设置
				set(newValue){
					this.lists.forEach(item=> {
						item.isSelect = newValue
					});
				},
				get(){
					if(this.lists.length == 0){
						return false;
					}
					return !this.lists.filter(item=>{
						return !item.isSelect
					}).length
				}
			}
		},
		methods: {
			handlerRemove(index,e){
				this.lists.splice(index,1)			
			},
			addDate(){
				if(!this.message.trim()){
					alert('新建任务不能为空')
					return
				}
				this.lists.push({
					text:this.message.trim(),
					isSelect:false
				})			
				this.message = ""	
			},
			isShow(item){
				switch(this.liststatus){
					/* case 'all':
					return true
					break; */

					case 'active':
					// if(item.isSelect==false){
					// 	return true
					// }
					return !item.isSelect
					break;

					case 'completed':
					return item.isSelect
					break;

					default :
					return true
					break;
				}
			}
		},
		mounted () {
			var todoDate = JSON.parse(localStorage.getItem('todoLists'))
			if(todoDate){
				this.lists = todoDate
			}else{
				this.lists = []
			}
		},
		updated(){
			localStorage.setItem('todoLists',JSON.stringify(this.lists))
		}
	})

})(window);
